package com.rupyi.service.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rupyi.service.domain.ExampleItem;
import com.rupyi.service.domain.vo.ExampleItemVo;
import com.rupyi.service.mapper.ExampleItemMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
@RequiredArgsConstructor
public class ExampleItemService {

    private final ExampleItemMapper baseMapper;

    public ExampleItemVo retrieveVoById(String id) {
        return baseMapper.selectVoById(id);
    }

    public List<ExampleItemVo> retrieveByPids(Collection<String> idList) {
        List<ExampleItem> itemList = baseMapper.selectList(new LambdaQueryWrapper<ExampleItem>()
            .in(ExampleItem::getPid, idList));
        if (CollectionUtil.isEmpty(itemList)) {
            return Collections.emptyList();
        }

        return BeanUtil.copyToList(itemList, ExampleItemVo.class);
    }


}
